package com.gitee.wsl.doc.opml

import com.gitee.wsl.doc.SampleReader
import com.gitee.wsl.doc.opml.bean.Opml
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue


class ScriptingNewsDirectoryTest {
    @Test
    @Throws(OpmlParseException::class)
    fun test() {
        val opml: Opml = SampleReader.parse("/opml/scriptingNewsDirectory.opml")

        assertEquals("2.0", opml.version)

        assertEquals("scriptingNewsDirectory.opml", opml.head.title)

        assertEquals("Thu, 13 Oct 2005 15:34:07 GMT", opml.head.dateCreated)
        assertEquals("Tue, 25 Oct 2005 21:33:57 GMT", opml.head.dateModified)
        assertEquals("Dave Winer", opml.head.ownerName)
        assertEquals("dwiner@yahoo.com", opml.head.ownerEmail)
        assertTrue(opml.head.expansionState!!.isEmpty())
        assertTrue(1 == opml.head.vertScrollState)
        assertTrue(105 == opml.head.windowTop)
        assertTrue(466 == opml.head.windowLeft)
        assertTrue(386 == opml.head.windowBottom)
        assertTrue(964 == opml.head.windowRight)

        assertEquals(8, opml.body.outlines.size)

        val iterator = opml.body.outlines.iterator()

        var outline = iterator.next()
        assertEquals("Scripting News sites", outline.getAttribute("text"))
        assertEquals("Sun, 16 Oct 2005 05:56:10 GMT", outline.getAttribute("created"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals(
            "http://hosting.opml.org/dave/mySites.opml",
            outline.getAttribute("url")
        )

        outline = iterator.next()
        assertEquals("News.Com top 100 OPML", outline.getAttribute("text"))
        assertEquals("Tue, 25 Oct 2005 21:33:28 GMT", outline.getAttribute("created"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals(
            "http://news.com.com/html/ne/blogs/CNETNewsBlog100.opml",
            outline.getAttribute("url")
        )

        outline = iterator.next()
        assertEquals("BloggerCon III Blogroll", outline.getAttribute("text"))
        assertEquals("Mon, 24 Oct 2005 05:23:52 GMT", outline.getAttribute("created"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals(
            "http://static.bloggercon.org/iii/blogroll.opml",
            outline.getAttribute("url")
        )

        outline = iterator.next()
        assertEquals("TechCrunch reviews", outline.getAttribute("text"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals(
            "http://hosting.opml.org/techcrunch.opml.org/TechCrunch.opml",
            outline.getAttribute("url")
        )

        outline = iterator.next()
        assertEquals(
            "Tod Maffin's directory of Public Radio podcasts",
            outline.getAttribute("text")
        )
        assertEquals("link", outline.getAttribute("type"))
        assertEquals("http://todmaffin.com/radio.opml", outline.getAttribute("url"))

        outline = iterator.next()
        assertEquals("Adam Curry's iPodder.org directory", outline.getAttribute("text"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals(
            "http://homepage.mac.com/dailysourcecode/DSC/ipodderDirectory.opml",
            outline.getAttribute("url")
        )

        outline = iterator.next()
        assertEquals("Memeorandum", outline.getAttribute("text"))
        assertEquals("Thu, 13 Oct 2005 15:19:05 GMT", outline.getAttribute("created"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals("http://tech.memeorandum.com/index.opml", outline.getAttribute("url"))

        outline = iterator.next()
        assertEquals("DaveNet archive", outline.getAttribute("text"))
        assertEquals("Wed, 12 Oct 2005 01:39:56 GMT", outline.getAttribute("created"))
        assertEquals("link", outline.getAttribute("type"))
        assertEquals("http://davenet.opml.org/index.opml", outline.getAttribute("url"))
    }
}